Replace Text Action Icon

Replace Text

Declaration

<AMREPLACE TEXT="test" FIND="test" REPLACE="test" RESULTVARIABLE="text [variable name]" USERE="YES" USECASE="YES" INDEX="6" MAXMATCHES="6" TOTALMATCHESVAR="text [variable name]">

See Also

Create Variable Send Keystrokes

Description

Finds and replaces each or every occurrence of a text pattern and places the result into a variable.  Regular expressions may be used for added power and flexibility.

Practical Usage

Used to find and replace a word or phrase inside of a larger piece of text .

Parameters

General Tab

Text
Text, Required
MARKUP: TEXT="My Name is Joe"

Specifies target text to be searched.  

Find
text,Required
MARKUP: FIND="Joe"

Specifies the text to search for.

Replace With
text,Required
MARKUP: REPLACE="Jim"

Specifies the text to replace the found text with.

Case Sensitive
Yes/No, Optional (default: No)
MARKUP: USECASE="YES"

Specifies whether the search performed should be case sensitive.  

Regular Expression
Yes/No, Optional (default: No)
MARKUP: USERE="YES"

Specifies whether the FIND parameter is a regular expression. If the option is no, the Find parameter contains literal text, if the option is yes, the find parameter contains a regular expression.

Populate Variable with first result
Text [variable name], Required
MARKUP: RESULTVARIABLE="varname"

Specifies the variable to receive the new text.

Advanced Tab

Starting at the following instance
Number, Optional (default: 1)
MARKUP: INDEX="5"

Specifies target text to be searched.  

Maximum Replacements
Text [variable name], Optional (default:0)
MARKUP: MAXMATCHES="6"

Specifies the maximum number of replacements that should be made. If 0(default) is specified, all instances of the found text will be replaced.

Total Replacement Count into variable
Text [variable name], Required
MARKUP: TOTALMATCHESVAR="varname"

Specifies the variable to receive the total number of replacements that were made.

Notes

Using Variables
All variables must be created before they can be used. This is done using the
Create Variable <AMVARIABLE> action. Once created, variables can be set using the Set Variable <AMSET> action, or by certain actions that support populating variables. To get data out of the variables, in any action parameter, simply surround the variable name with percentage % signs (e.g. %varname%). Remember not to use percentage signs when specifying the name of a variable to populate, percentage signs are only needed to get data out.

Standard Error Handling Options
This action also includes the standard "Error Causes" and "On Error" failure handling options/tabs

More on Error Handling Options

Variables and Expressions
All text fields allow the use of expressions by surrounding the expression in percentage signs (example: %MYVARIABLE%, %Left('Text',2)%). To help construct these expressions, a popup expression builder is available in all these fields by pressing F2.
More on variables...

More on expressions...

More on the expression builder...

Example

<AMVARIABLE NAME="sourcedata">AutoMate Version 5.5 Adds Power, Speed, Flexibility and Intelligence.</AMVARIABLE>
<AMVARIABLE NAME="newdata"></AMVARIABLE>
<AMREPLACE TEXT="%sourcedata%" FIND="Speed" REPLACE="Good Looks" RESULTVARIABLE="newdata">
<AMMESSAGEBOX>BEFORE: %sourcedata%

AFTER: %newdata%</AMMESSAGEBOX>